package com.hospital.frontdesk.fronxiang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.hospital.frontdesk.fronxiang.dao.FrontdeskCardMapper;
import com.hospital.frontdesk.fronxiang.entity.FrontdeskCard;
import com.hospital.frontdesk.fronxiang.service.FrontdeskCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description：业务层实现类
 * @author：xyj
 * @date：2021/9/7 20:57
 * @versions：v1.0
 */
@Service
public class FrontdeskCardServiceImpl implements FrontdeskCardService {
    @Autowired
    private FrontdeskCardMapper frontdeskCardMapper;

    @Override
    public boolean register(FrontdeskCard frontdeskCard) {
        int insert = frontdeskCardMapper.insert(frontdeskCard);
        if (insert == 1)
            return true;
        return false;
    }

    @Override
    public List<FrontdeskCard> pagefrontdeskcard(Integer id, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        return frontdeskCardMapper.pagefrontdeskcard(id);
    }

    @Override
    public boolean frontdeskcardupdate(Integer id) {
        int del = frontdeskCardMapper.deleteById(id);
        if (del == 1)
            return true;
        return false;
    }

    @Override
    public boolean recharging(Integer id, Double money) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("money", money);
        Integer update = frontdeskCardMapper.update(map);
        if (update == 1)
            return true;
        return false;
    }

    @Override
    public FrontdeskCard id(String idCard) {
        QueryWrapper<FrontdeskCard> wrapper = new QueryWrapper<>();
        wrapper.eq("idCard", idCard);
        return frontdeskCardMapper.selectOne(wrapper);
    }

    @Override
    public FrontdeskCard selectById(Integer id) {
        QueryWrapper<FrontdeskCard> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        return frontdeskCardMapper.selectOne(wrapper);
    }
}
